package com.system.controller;

import com.order.hit.crossover.platform.common.dao.StoreValueDao;
import com.order.hit.crossover.platform.common.utils.PFResponse;
import com.system.service.StoreValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/StoreValue")
public class StoreValueController
{
    @Autowired
    @Qualifier("StoreValueServiveImpl")
    private StoreValueService valueService;

    @GetMapping("/getByStoreId/{storeId}")
    public PFResponse getStoreValue(@PathVariable("storeId") String storeId) {
        StoreValueDao valueDao = valueService.getByStoreId(storeId);
        PFResponse resp = new PFResponse();
        resp.code(200);
        resp.message("查询成功！");
        resp.data(valueDao);
        return resp;
    }

    @PostMapping("/add")
    public PFResponse addStoreValue(@RequestBody StoreValueDao valueDao) {
        int code = 0;
        String message = "";
        try
        {
            valueService.add(valueDao);
            message = "添加成功！";
            code = 200;
        }catch(Exception e) {
            message = "添加失败！";
            code = 500;
        }

        return new PFResponse().code(code).message(message);
    }

    @PostMapping("/update")
    public PFResponse updateStoreValue(@RequestBody StoreValueDao valueDao) {
        int code = 0;
        String message = "";

        try
        {
            valueService.update(valueDao);
            code = 200;
            message = "修改成功！";
        }catch(Exception e) {
            code = 500;
            message = "修改失败！";
        }

        return new PFResponse().code(code).message(message);
    }

    @PostMapping("/delete/{storeId}")
    public PFResponse deleteStoreValue(@PathVariable("storeId") String storeID) {

        String message = "";
        int code = 0;
        try{
            valueService.deletebyStoreId(storeID);
            code = 200;
            message = "删除成功！";
        }catch(Exception e) {
            code = 500;
            message = "删除失败！";
            e.printStackTrace();
        }

        return new PFResponse().code(code).message(message);
    }
}
